using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using zevenseas.Community.Web.UI.WebControls.WebParts;

namespace zevenseas.Community.Web.UI.WebControls.WebParts
{
    public class CodeplexStatisticsEditor : EditorPart
    {
        private TextBox releasesBox;
        private Panel dispPanel;

        protected override void OnInit(EventArgs e)
        {
            this.Title = "Codeplex Statistics";
            base.OnInit(e);
        }

        protected override void CreateChildControls()
        {
            releasesBox = new TextBox();
            releasesBox.Rows = 5;
            releasesBox.TextMode = TextBoxMode.MultiLine;

            dispPanel = new Panel();

            Label instructions = new Label();
            instructions.Text = "Enter the URL to your releases, for example: http://www.codeplex.com/zevenseas/Release/ProjectReleases.aspx?ReleaseId=15157, using ';' to seperate them.";
            dispPanel.Controls.Add(instructions);
            
            dispPanel.Controls.Add(new LiteralControl("</br>Release URLs:</br>"));
            dispPanel.Controls.Add(releasesBox);

            LinkConductorTagLine productTagLine = new LinkConductorTagLine();
            productTagLine.ProductName = "CodeplexStatisticsWebPart";
            productTagLine.Action = "Information";
            dispPanel.Controls.Add(productTagLine);

            Controls.Add(dispPanel);

            base.CreateChildControls();
        }

        public override bool ApplyChanges()
        {
            EnsureChildControls();
            CodeplexStatistics webPart = WebPartToEdit as CodeplexStatistics;
            if (webPart != null)
            {
                if (!string.IsNullOrEmpty(releasesBox.Text)) webPart.AllReleases = releasesBox.Text;
            }
            return true;
        }

        public override void SyncChanges()
        {
            EnsureChildControls();
            CodeplexStatistics webPart = WebPartToEdit as CodeplexStatistics;

            if (webPart != null)
            {
                releasesBox.Text = webPart.AllReleases;
            }
        }
 
    
    }
}